/*
 * @Author: bill
 * @Date: 2020-07-15 09:11:11
 * @LastEditTime: 2020-07-15 17:51:02
 * @Description: 
 */ 
var $ = require("jquery");
import {getUrlString} from 'utils/index'
/**
 * 微信授权
 */
const wxverify = {
    mounted () {
    },
    methods: {
        wxAjax (url, title, shareimg, desc) {
            var me = this;
            let jsApiList = [
                'onMenuShareTimeline', // 分享到朋友圈
                'onMenuShareAppMessage', // 分享到朋友
                'onMenuShareQQ', // 分享到QQ
                'onMenuShareTimeline', // 分享到朋友圈
                'closeWindow'
            ];
            let  urlHref = location.href.split('#')[0];
            $.ajax({
                url: process.env.BASE_API+'H5/user/shareParams',
                type: 'post',
                dataType: 'json',
                data: {
                    url: encodeURIComponent(urlHref),
                }
            }).done((res) => {
                console.log(res);
                // let data = res.data
                let data = res.data
                // $store.commit('wxConfig', window.location.href)
			    // wx.config(data)
                wx.config({
                    debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
                    appId: data.appId, // 必填，公众号的唯一标识
                    timestamp: String(data.timestamp), // 必填，生成签名的时间戳
                    nonceStr: data.nonceStr, // 必填，生成签名的随机串
                    signature: data.signature, // 必填，签名，见附录1
                    jsApiList: jsApiList // 必填，需要使用的JS接口列表，所有JS接口列表见附录2
                })
                wx.ready(function (){
                    var shareData = {
                        title: title,
                        desc: desc,//这里请特别注意是要去除html 
                        link: url,
                        imgUrl: shareimg
                    };
                    wx.onMenuShareAppMessage(shareData);
                    wx.onMenuShareTimeline(shareData);
                    wx.onMenuShareQQ(shareData);
                    wx.onMenuShareWeibo(shareData);
                });
                console.log('success', data)
            }).fail((error) => {
                console.log('error', error)
            }).always((complete) => {
                console.log('complete', complete)
            })
        },
        
        
    }
}
export default wxverify
